#include "stdint.h"
#include "stdio.h"
#include "n32g031.h"
#include "DevicesInput.h"

void vInputInit(void)
{
    GPIO_InitType GPIO_InitStructure = {0};

    /* -1- Enable GPIOx Clock (to be able to program the configuration registers) */
    RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOC, ENABLE);

    /* -2- Configure GPIOx_PIN in output push-pull mode */
    GPIO_InitStruct(&GPIO_InitStructure);
    GPIO_InitStructure.Pin = GPIO_PIN_15;
    GPIO_InitStructure.GPIO_Mode = GPIO_MODE_INPUT;
    GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP;
    GPIO_InitPeripheral(GPIOC, &GPIO_InitStructure);
}

uint32_t uiInputValueGet(void)
{
    uint32_t uiValue = INPUT_CHANNEL_DUST;
    uint8_t i = 0;

    for(i = 0; i < 8; ++i)
    {
        if(RESET != GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_15))
            uiValue &= ~INPUT_CHANNEL_DUST;
    }

    return uiValue;
}
